const fs = require('fs')
const path = require('path')
//新闻列表
function news(){
    let filePath = path.join(__dirname,'./data/news.json')
    let str = fs.readFileSync(filePath,'utf-8')
    return JSON.parse(str)
}
//学生列表
function students(){
    let filePath = path.join(__dirname,'./data/info.json')
    let str = fs.readFileSync(filePath,'utf-8')
    return JSON.parse(str)
}
//抽取幸运学生
function lucystar(){
    let list = students()
    let index = Math.floor(Math.random()*list.length)
    list[index].count++
    let filePath = path.join(__dirname,'./data/info.json')
    fs.writeFileSync(filePath,JSON.stringify(list))
    return list[index]
}
//导出，导出才可以被后面的模块取到
module.exports = {
    news,
    students,
    lucystar
}